#include "VertexBuffer.h"

VertexBuffer::VertexBuffer()
{
    mType = kXBufferObjectTypeVertexBuffer;
    mVertexes = nullptr;
    mVertexCount = 0;
}

VertexBuffer::~VertexBuffer()
{
    if (mVertexes)
    {
        delete[] mVertexes;
        mVertexes = nullptr;
    }
}

void VertexBuffer::SetSize(int count)
{
    mVertexCount = count;
    if (mVertexes)
    {
        delete[] mVertexes;
    }
    mVertexes = new XVertexData[count];

    XBufferObject::OnSetSize();
}

int VertexBuffer::GetSize()
{
    return mVertexCount * sizeof(XVertexData);
}

void VertexBuffer::SetPosition(int index, float x, float y, float z, float w)
{
    mVertexes[index].SetPosition(x, y, z, w);
}

void VertexBuffer::SetTexcoord(int index, float x, float y, float z, float w)
{
    mVertexes[index].SetTexcoord(x, y, z, w);
}

void VertexBuffer::SetNormal(int index, float x, float y, float z, float w)
{
    mVertexes[index].SetNormal(x, y, z, w);
}

void VertexBuffer::SetTangent(int index, float x, float y, float z, float w)
{
    mVertexes[index].SetTangent(x, y, z, w);
}

void VertexBuffer::SubmitData()
{
    XBufferObject::SubmitData(mVertexes, GetSize());
}
